package com.hntest.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hntest.entity.BidRequest;
import com.hntest.entity.Pager;
import com.hntest.entity.UserFile;
import com.hntest.service.impl.BidRequestServiceImpl;
import com.hntest.service.impl.UserFileServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller("bidRequestController")
public class BidRequestController {
    @Autowired
    private BidRequestServiceImpl bidRequestService;

    public void setBidRequestService(BidRequestServiceImpl bidRequestService) {
        this.bidRequestService = bidRequestService;
    }

    @RequestMapping(value = "/admin/bidRequestSelect", method = {RequestMethod.GET, RequestMethod.POST})
    public String select(Pager pager, BidRequest bidRequest, ModelMap modelMap, HttpServletRequest request){
        System.out.println("3333333333333333333333333");
        List<BidRequest> list=bidRequestService.getListByPage(pager,bidRequest);

        modelMap.put("list", list);
        modelMap.put("pager",pager);
        modelMap.put("bidRequest",bidRequest);
        return "admin/bidRequestselect";
    }

    @RequestMapping(value = "/admin/bidRequestSelect1", method = {RequestMethod.GET, RequestMethod.POST})
    public String select1(Pager pager1, BidRequest bidRequest1, ModelMap modelMap1, HttpServletRequest request){
        System.out.println("---------------------------->");
        List<BidRequest> list1=bidRequestService.getListByPage1(pager1,bidRequest1);

        modelMap1.put("list1", list1);
        modelMap1.put("pager1",pager1);
        modelMap1.put("bidRequest1",bidRequest1);
        return "admin/bidRequestselect1";
    }

    @RequestMapping(value = "/admin/bidRequestSelect2", method = {RequestMethod.GET, RequestMethod.POST})
    public String select2(Pager pager, BidRequest bidRequest, ModelMap modelMap, HttpServletRequest request){
        List<BidRequest> list=bidRequestService.getListByPage2(pager,bidRequest);

        modelMap.put("list", list);
        modelMap.put("pager",pager);
        modelMap.put("bidRequest",bidRequest);
        return "admin/bidRequestselect2";
    }

    @RequestMapping(value = "/admin/bidRequestUpdate",method= {RequestMethod.GET,RequestMethod.POST},
            produces= {"application/JSON;charset=utf-8"})//提交更新后的数据，成功后重定向到分页查询
    @ResponseBody
    public Object Update(BidRequest bidRequest){
        System.out.println(bidRequest);
        int n =  bidRequestService.update(bidRequest);
        BidRequest bidRequest1 = null;
        JSONObject jsonObject = new JSONObject();
        if (n>0){
            bidRequest1 = bidRequestService.getBidRequestById(bidRequest.getBidRequestId());
            jsonObject.put("success",true);
        }else{
            jsonObject.put("success",false);
            jsonObject.put("msg","系统异常，审核出错");
        }
        jsonObject.put("msg",bidRequest1.getState());
        return JSON.toJSONString(jsonObject);
    }
}
